<?php foreach ($items as $item): ?>
	<tr>
		<td>
			<div class="icon50">
				<? $item_main_img = !is_null($item->itemImages) ? $item->itemImages : false; ?>
				<? if ( $item_main_img ): ?>
					<img src=" <?= $this->baseUrl . $item_main_img[0]->img_url ?>" class="round50">
				<? endif; ?>
			</div>
		</td>
		<td>
			<a class="ajax-load" href="#edit" data-page="<?= CHtml::normalizeUrl(array('catalog/Restaurant','id'=>$item->id))?>">
				<?= $item->title ?>
			</a>
		</td>
		<td class="skip" style="text-align: center;">
			<select class="ajax-switch isVisibli" data-id="<?= $item->id ?>">
				<option value="1"<?= ($item->isVisible)?" selected":"" ?>></option>
				<option value="0"<?= (!$item->isVisible)?" selected":"" ?>></option>
			</select>
		</td>
		<td class="skip"> 
			<div class="btn-group">
				<a class="btn btn-green icon ajax-load" title="Редактировать" href="#edit" data-page="<?= CHtml::normalizeUrl(array('catalog/Restaurant','id'=>$item->id))?>">i</a>
				<a class="btn btn-green icon" title="Меню" href="<?= CHtml::normalizeUrl(array('catalog/menu', 'id'=>$item->id))?>">f</a>
				<a class="btn btn-green icon confirm-delete" title="Удалить" href="<?= CHtml::normalizeUrl(array('catalog/DeletedRestaurant','id'=>$item->id))?>">g</a>
			</div>
		</td>
	</tr>
<?php endforeach ?>

<tr>
	<td id="itemcount" style="display:none">
		<?= $itemCount ?>
	</td>
</tr>

<script type="text/javascript">
	$(function() {
        $('.search > .input#search-input').keyup(function() { $(this).change(); });
        $('.search > .input#search-input').change(function() {
            value = $(this).val();
            $('#items > tr').each(function() {
                tr = $(this);
                b = false;
                $('td:not(.skip)', tr).each(function() {
                    if($(this).text().toLowerCase().indexOf(value) >= 0)
                        b = true;
                });
                if(!b) tr.hide(100);
                else tr.show(100);
            });
        });
		$('.ajax-load').unbind('click');
		$('.ajax-load').click(function(event) {
			event.stopPropagation();
			$.ajax($(this).data('page')).done(function(data) {
				popup(data);
			});
			return false;
		});
		$('.confirm-delete').unbind('click');
		$('.confirm-delete').click(function() {
			var isConfirmed = confirm('Вы уверены?');
			if (isConfirmed) return true;
			else return false;
		});

		var ajaxSwitchIDisVisi = 0;
		$('.ajax-switch.isVisibli').each(function() {
			$(this).attr('data-sid', ajaxSwitchIDisVisi);
			temp = "";
			leftSpace = "";
			if ($(this).val() == 1) {
				temp = " true";
				leftSpace = "style='left: 1em;'"
			}
			$(this).after("<div class='ajax-switcher"+temp+" isVisibli' data-sid='"+ajaxSwitchIDisVisi+"' data-state='1'><div class='toggle' "+leftSpace+"></div></div>");
			$(this).hide();

			ajaxSwitchIDisVisi++;
		});

		$('.ajax-switcher.isVisibli').click(function() {
			$(this).toggleClass('true');
			
			var thisSwitch = $('.ajax-switch[data-sid="'+$(this).data('sid')+'"]');
			if($(this).hasClass('true')) {
				$('.toggle', $(this)).animate({'left' : '1em'}, 200);
				thisSwitch.val(1);
			} else {
				$('.toggle', $(this)).animate({'left': '0em'}, 200);
				thisSwitch.val(0);
			}
			$.get('<?=CHtml::normalizeUrl(array('catalog/RestauranVisible'))?>',{id:thisSwitch.data('id'), status:thisSwitch.val()}).done(humane.log('Изменено'));
		});
	})
</script>